<?php
	$ssFilter 		= $this->arrParam['ssFilter'];
	$phongban_name = '';
	
	$nhanvien_name = '';
	if(!empty($this->Nhanvien['name'])) {
		$nhanvien_name = ' của ' . $this->Nhanvien['name'];
		if(!empty($this->Phongban['name'])) {
			$nhanvien_name = $this->Nhanvien['name'] . ' (' . $this->Phongban['name'] . ') ';
		}
	} else {
		if(!empty($this->Phongban['name'])) {
			$nhanvien_name = ' của ' . $this->Phongban['name'];
		}
	}
?>
<form action="" method="post" name="appForm">
<div id="columnSortable">
	<div id="dashlet1" class="dragbox width67">
		<script type="text/javascript">
			gvChartInit();
			$(document).ready(function(){
				$('#doanhthu').gvChart({
					chartType: 'LineChart',//AreaChart,LineChart,BarChart,ColumnChart,PieChart
					gvSettings: {
						vAxis: {title: 'x 1.000.000 VNĐ'},
						hAxis: {title: ''},
						width: 0,
						height: 250
					}
				});
				
			});
		</script>
		<div class="block_khung goc5">
			<div class="block_title goc3">
				<span class="toggleBlock db-up" id="block_1">&nbsp;</span>
				Doanh số bán hàng
				<div class="viewAll">
				<?php
					$linkSlbPhongban 	= $this->baseUrl('default/admin/filter/type/id_phongban');
					$selectPhongban 	= $this->cmsSelect('id_phongban', $ssFilter['id_phongban'], $this->slbPhongban, array('onchange'=>"OnSubmitForm('" .$linkSlbPhongban ."')", 'class' => 'select'));
	
					$linkSlbNhanvien 	= $this->baseUrl('default/admin/filter/type/id_nhanvien');
					$selectNhanvien 	= $this->formSelect('id_nhanvien', $ssFilter['id_nhanvien'], array('onchange'=>"OnSubmitForm('" .$linkSlbNhanvien ."')", 'class' => 'select'), $this->slbNhanvien);
	
					for ($i = @date('Y'); $i >= 2010; $i--) {
						$optionsNam[$i] = $i;
					}
					$linkSlbNam 		= $this->baseUrl('default/admin/filter/type/date_nam');
					$selectNam 			= $this->formSelect('date_nam', $ssFilter['date_nam'], array('onchange'=>"OnSubmitForm('" .$linkSlbNam ."')", 'class' => 'select'), $optionsNam);
					
					echo $selectPhongban;
					echo $selectNhanvien;
					echo $selectNam;
				?>
				</div>
			</div>
			<div class="block_content" id="block_1">
				<table id="doanhthu">
					<caption style="text-align: center;">Doanh số bán hàng <?php echo $nhanvien_name;?> năm <span id="bieudo_nam"><?php echo $ssFilter['date_nam'];?></span></caption>	
					<thead>
						<tr>
							<th></th>
							<th>T.1</th>
							<th>T.2</th>
							<th>T.3</th>
							<th>T.4</th>
							<th>T.5</th>
							<th>T.6</th>
							<th>T.7</th>
							<th>T.8</th>
							<th>T.9</th>
							<th>T.10</th>
							<th>T.11</th>
							<th>T.12</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<th>Thực thu</th>
							<?php
							for ($i = 1; $i <= 12; $i++){
								$HdDongia			= $this->Items[$i]['hd_dongia'];
								$HdThanhtien	= 0;
								if(!empty($this->Items[$i]['hd_thanhtien'])) {
									$HdThanhtien		= ($this->Items[$i]['hd_thanhtien']) / 1000000;
								}
								$HdDadong		 	= $this->Items[$i]['hd_sotiendadong'];
								$HdSotienno		 	= $this->Items[$i]['hd_sotienno'];
							?>
							<td><?php echo $HdThanhtien;?></td>
							<?php
								} 
							?> 
						</tr>
						<tr>
							<th>Đã thu</th>
							<?php
							for ($i = 1; $i <= 12; $i++){
								$HdDongia			= $this->Items[$i]['hd_dongia'];
								$HdThanhtien	= 0;
								if(!empty($this->Items[$i]['hd_thanhtien'])) {
									$HdThanhtien		= ($this->Items[$i]['hd_thanhtien']) / 1000000;
								}
								$HdDadong = 0;
								if(!empty($this->Items[$i]['hd_sotiendadong'])) {
									$HdDadong		 	= $this->Items[$i]['hd_sotiendadong'] / 1000000;
								}
								$HdSotienno		 	= $this->Items[$i]['hd_sotienno'];
							?>
							<td><?php echo $HdDadong;?></td>
							<?php
								} 
							?> 
						</tr>
					</tbody>
				</table>
			</div>
		</div>
				
	</div>
	<div id="dashlet2" class="dragbox width33">
		<div class="block_khung goc5">
			<div class="block_title goc3">
				<span class="toggleBlock db-up" id="block_2">&nbsp;</span>
				<a href="<?php echo $this->baseUrl('marketing/admin-item/index');?>">Chiến dịch mới</a>
			</div>
			<div class="block_content" id="block_2" style="background: #FFF; padding-top: 3px;">
				<table class="tblList">
					<tr>
						<th width="20">STT</th>
						<th>Tên chiến dịch</th>
						<th width="100">Ngày kết thúc</th>
					</tr>
					<?php
					if(count($this->Marketing) > 0) {
					foreach ($this->Marketing as $key => $val){ 
						$id 			= $val['id'];
						$name 			= $val['name'];
						$ngaybatdau		= $val['ngaybatdau'];
						$ngayketthuc	= $val['ngayketthuc'];
							
						$linkInfo		= $this->baseUrl('marketing/admin-item/info/id/' . $id);

						$name 	= '<a href="javascript:void(0)">' . $name . '</a>';
						$classRow = 'row1';
						if($key % 2 == 0)
							$classRow = '';
					?>
					<tr class="<?php echo $classRow;?>">
						<td align="center"><?php echo $key + 1;?></td>
						<td align="left"><?php echo $name;?></td>
						<td align="center"><?php echo $ngayketthuc;?></td>
					</tr>
					<?php
					} 
					}
					?>
				</table>
			</div>
		</div>
	</div>
	<div id="dashlet3" class="dragbox width50">
		<div class="block_khung goc5">
			<div class="block_title goc3">
				<span class="toggleBlock db-up" id="block_3">&nbsp;</span>
				<a href="<?php echo $this->baseUrl('khachhang/admin-item/index/tn/1');?>">Top khách hàng tiềm năng</a>
				<span class="viewAll"><a href="<?php echo $this->baseUrl('khachhang/admin-item/index/tn/1');?>">Xem tất cả</a></span>
			</div>
			<div class="block_content" id="block_3" style="background: #FFF; padding-top: 3px;">
				<table class="tblList">
					<tr>
						<th width="20">STT</th>
						<th>Tên khách hàng</th>
						<th width="100">Điện thoại</th>
						<th width="180">Email</th>
						<th width="75">Ngày tạo</th>
					</tr>
					<?php
					if(count($this->Khachhang) > 0) {
					foreach ($this->Khachhang as $key => $val){ 
						$id 			= $val['id'];
						$name 			= $val['name'];
						$phone 			= $val['phone'];
						if(!empty($val['phone'])) {
							$phone		= $val['telephone'];
						}
						$email 			= $val['email'];
						$created		= $val['created'];
							
						$linkEdit		= $this->baseUrl('khachhang/admin-khcn/edit/tn/1/id/' . $id);
						if ($val['id_cat'] == 2) {
							$linkEdit	= $this->baseUrl('khachhang/admin-khtc/edit/tn/1/id/' . $id);
						}

						$name 	= '<a href="'.$linkEdit.'">' . $name . '</a>';
						$classRow = 'row1';
						if($key % 2 == 0)
							$classRow = '';
					?>
					<tr class="<?php echo $classRow;?>">
						<td align="center"><?php echo $key + 1;?></td>
						<td align="left"><?php echo $name;?></td>
						<td align="center"><?php echo $phone;?></td>
						<td align="left"><?php echo $email;?></td>
						<td align="center"><?php echo $created;?></td>
					</tr>
					<?php
					} }
					?>
				</table>
			</div>
		</div>
	</div>
	<div id="dashlet4" class="dragbox width50">
		<div class="block_khung goc5">
			<div class="block_title goc3">
				<span class="toggleBlock db-up" id="block_4">&nbsp;</span>
				<a href="<?php echo $this->baseUrl('hopdong/admin-item/index');?>">Danh sách hợp đồng mới</a>
				<span class="viewAll"><a href="<?php echo $this->baseUrl('hopdong/admin-item/index');?>">Xem tất cả</a></span>
			</div>
			<div class="block_content" id="block_4" style="background: #FFF; padding-top: 3px;">
				<table class="tblList">
					<tr>
						<th width="20">STT</th>
						<th width="100">Mã hợp đồng</th>
						<th>Tên khách hàng</th>
						<th width="70">Giá trị <span class="note">(VNĐ)</span></th>
						<th width="75">Còn nợ <span class="note">(VNĐ)</span></th>
						<th width="75">Ngày ký</th>
					</tr>
					<?php
					if(count($this->Hopdong) > 0) {
					foreach ($this->Hopdong as $key => $val){ 
						$id 			= $val['id'];
						$code 			= strtoupper($val['khachhang_code']) . '-' . $val['id'];
						$khachhang_name = $val['khachhang_name'];
						$hd_thanhtien	= $val['hd_thanhtien'];
						$hd_sotienno	= $val['hd_sotienno'];
						if($val['hd_sotienno'] > 0) {
							$hd_sotienno = '<span class="red auto_numberic">' . $val['hd_sotienno'] . '</span>';
						}
						$ngayky			= $val['ngayky'];
						$nhanvien_name 	= $val['nhanvien_name'];
						if(!empty($val['nhanvien_alias'])) {
							$nhanvien_name = $val['nhanvien_name'] . ' (' . $val['nhanvien_alias'] . ')';
						}
							
						$linkEdit		= $this->baseUrl('hopdong/admin-item/edit/id/' . $id);

						$khachhang_name = '<a href="'.$linkEdit.'">' . $khachhang_name . '</a>';
						$classRow = 'row1';
						if($key % 2 == 0)
							$classRow = '';
					?>
					<tr class="<?php echo $classRow;?>">
						<td align="center"><?php echo $key + 1;?></td>
						<td align="center"><?php echo $code;?></td>
						<td align="left"><?php echo $khachhang_name;?></td>
						<td align="right"><?php echo $hd_thanhtien;?></td>
						<td align="right"><?php echo $hd_sotienno;?></td>
						<td align="center"><?php echo $ngayky;?></td>
					</tr>
					<?php
					} }
					?>
				</table>
			</div>
		</div>
	</div>
	<div class="clr"></div>
</div>
</form>